#include<stdio.h>
#include<unistd.h>
#include<errno.h>
#include<fcntl.h>
#include<stdlib.h>
int main()
{
    
    int fd = open("/dev/ttyACM0",O_RDWR);
    if(fd == -1) exit(-2);
    
    char rx_buf[100];
    char tx_buf[100] = {0xff, 0xff, 0xbe, 0xef};
    
    int rcnt = 20;
    while(1)
    {
        
        int info = read(fd, rx_buf, rcnt);
        
        if(info == -1)
        { 
            printf("error");
            printf("%d",errno); 
            continue;
        }
        
        
        int pass;
        
        pass = 1;
        
        for(int i = 0; i < 9; ++ i)
        {
            if(rx_buf[i] != 0xff)
            {
                pass = 0;
                read(fd, rx_buf, rcnt);
                break;
            }
        }
        
        if(pass) break;
        
        printf("\r");
    
        for(int i = 9; i < 23; ++ i)
        {
            printf("%02X ",(unsigned char)rx_buf[i]);
        }
        
        
    }
       
    return 0;
}

